package sim1011.poltergeist;

import java.util.ArrayList;
import java.util.HashMap;

import sim1011.starter.EctoMobileStarter;
import sim1011.status.Status;

public class TrafficArbiter extends Arbiter {
	private final static int MAX_RANK_ON_MIGRATION = 70;
	private static final long serialVersionUID = 7703472244256258461L;
	private float cost;
	protected HashMap<String, Float> finalRank;
	protected Status status;

	public TrafficArbiter(Status s, float cost) {
		this.cost = cost;
		this.status = s;
	}

	@Override
	public void makeYourDecision(String component, String curContainer,
			ArrayList<String> availableNodes, HashMap<String, Float> finalRank) {
		this.finalRank = finalRank;
		if(availableNodes.contains(curContainer)) {
			finalRank.put(curContainer, finalRank.get(curContainer)+EctoMobileStarter.TRAFFIC_P*100.0f);
		} else {
			for(String node:availableNodes) {
				finalRank.put(node, finalRank.get(node)+EctoMobileStarter.TRAFFIC_P*status.getLinkQoS(node, curContainer));
			}
		}
		/*for (String node : availableNodes) {
			if (node.equals(curContainer)) {
				Float curRank = finalRank.get(node);
				Float newRank = curRank + this.cost
						* EctoMobileStarter.MAX_RANK_VAL;
				finalRank.put(node, newRank);
			} else {
				float curRank = finalRank.get(node).floatValue();
				float linkQoS = status.getNetworkMatrix()
						.getLinkQoS(curContainer, node).floatValue();
				float newRank = curRank
						+ this.cost
						* (linkQoS / EctoMobileStarter.MAX_NETWORK_LINK_QOS * MAX_RANK_ON_MIGRATION);
				finalRank.put(node, newRank);
			}
		}*/
	}
}
